package com.jumi.microservice.stock.controller;

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.BasePageResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.core.aspect.WebLog;
import com.jumi.microservice.common.exception.ExceptionSupply;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.domain.LogDetailVO;
import com.jumi.microservice.domain.OperateLogQuery;
import com.jumi.microservice.stock.domain.StockMaterialAlarmDTO;
import com.jumi.microservice.stock.dto.StockMaterialRequest;
import com.jumi.microservice.stock.dto.StockMaterialResponse;
import com.jumi.microservice.stock.service.LogService;
import com.jumi.microservice.stock.service.StockMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName StockMaterialController
 * @Description
 * @Author Abel Yang
 * @Date 2020/8/21/021 15:00
 **/
@RestController
@RequestMapping("/supply/stock/material")
@Api(tags = {"【仓库管理】库存管理接口"})
public class StockMaterialController extends BaseController {

    @Resource
    private StockMaterialService stockMaterialService;

    @Autowired
    private LogService logService;

    /**
     * @Description: 查询物料库存列表
     * @Param stockMaterialRequest
     * @Return {@link List<  StockMaterialResponse >}
     * @Throws
     * @Author Abel Yang
     * @Date 2020/8/22/022 14:26
     * @return
     */
    @PostMapping("/getListByPage")
    @ApiOperation("分页查询物料库存分页列表")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "goodsId", value = "产品id", dataType = "Long", paramType = "query"),
                    @ApiImplicitParam(name = "materialId", value = "物料id", dataType = "Long", paramType = "query"),
                    @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "String", paramType = "query"),
                    @ApiImplicitParam(name = "goodsName", value = "商品名称", dataType = "String", paramType = "query"),
                    @ApiImplicitParam(name = "goodsType", value = "商品类型", dataType = "Byte", allowableValues = "0,1", paramType = "query"),
                    @ApiImplicitParam(name = "status", value = "商品状态", dataType = "Byte", allowableValues = "0,1", paramType = "query"),
                    @ApiImplicitParam(name = "alarmed", value = "是否预警", dataType = "Boolean", paramType = "query"),
                    @ApiImplicitParam(name = "supplierId", value = "供应商id", dataType = "Long", paramType = "query"),
                    @ApiImplicitParam(name = "warehouseId", value = "仓库id", dataType = "Long", defaultValue = "0", paramType = "query"),
            })
    public TableDataInfo<List<StockMaterialResponse>> getStockMaterialListByPage(StockMaterialRequest stockMaterialRequest) {
        startPage();
        List<StockMaterialResponse> stockMaterialList = stockMaterialService.getStockMaterialList(stockMaterialRequest);
        return getDataTable(stockMaterialList);
    }

    @PostMapping("/setAlarmNum")
    @ApiOperation("设置物料预警值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "alarmNum", value = "预警值", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "materialId", value = "物料id", dataType = "Long", required = true, paramType = "query"),
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", dataType = "Long", required = true, paramType = "query"),
    })
    @WebLog(description = "设置物料预警值")
    public ResponseResult setAlarmNum(StockMaterialAlarmDTO stockMaterialAlarmDTO) {
        try {
            stockMaterialService.setAlarmNum(stockMaterialAlarmDTO);
        } catch (ExceptionSupply e) {
            e.printStackTrace();
            return ResponseResult.error(500, e.getMessage());
        }
        return ResponseResult.success("操作成功",true);
    }

    /**
     * 操作日志分页查询
     *
     * @param operateLogQuery 账号查询条件
     * @return 账号操作日志集合
     */
    @ApiOperation(value = "标签操作日志分页查询", notes = "标签操作日志分页数据")
    @GetMapping(value = "/log")
    public BasePageResponse<List<LogDetailVO>> lisOperateLogByPage(OperateLogQuery operateLogQuery) {
        return logService.listOperateLogs(operateLogQuery);
    }
}
